<template>
<el-container style=" border: 1px solid #eee">
  <el-aside width="200px">
    <el-menu :default-openeds="['1']" style="background-color: #041a63">
      <el-submenu index="1">
        <template slot="title"><i class="el-icon-message"></i><span style="color: white">商品管理</span></template>
        <el-menu-item index="1-1" @click="productList">商品列表</el-menu-item>
        <el-menu-item index="1-2" @click="queryproduct">商品查询</el-menu-item>
        <el-menu-item index="1-3">商品统计</el-menu-item>
        <el-menu-item index="1-4">商品出库</el-menu-item>
      </el-submenu>
      <el-submenu index="2">
        <template slot="title"><i class="el-icon-menu"></i><span style="color: white">定单管理</span></template>
        <el-menu-item index="2-1">选项1</el-menu-item>
        <el-menu-item index="2-2">选项2</el-menu-item>
      </el-submenu>
    </el-menu>
  </el-aside>
  <el-container>
    <el-header style="text-align: right; font-size: 12px ;height: 56px">
      <el-dropdown>
        <i class="el-icon-setting" style="margin-right: 15px"></i>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>查看</el-dropdown-item>
          <el-dropdown-item>新增</el-dropdown-item>
          <el-dropdown-item>删除</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <span>王小虎</span>
    </el-header>
    <el-main>

      <el-table :data="tableData" style="width: 100%" :row-class-name="tableRowClassName">
        <el-table-column prop="id" label="ID" width="80"> </el-table-column>
        <el-table-column prop="productName" label="产品名称" width="120"> </el-table-column>
        <el-table-column prop="price" label="价格" width="100"> </el-table-column>
        <el-table-column prop="stock" label="库存"> </el-table-column>
      </el-table>

    </el-main>
  </el-container>
</el-container>
</template>

<script>
import {
  productList
} from "@/api/productAPI.js";
//import axios from "axios";

export default {
  data() {
    const item = {
      date: "2016-05-02",
      name: "王小虎",
      address: "",
    };
    return {
      tableData: Array(5).fill(item),
    };
  },
  mounted() {},
  methods: {
    tableRowClassName({
      row,
      rowIndex
    }) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    setContainerHeight() {
      const windowHeight = window.innerHeight;
      this.$refs.container.style.height = `${windowHeight}px`;
    },
    queryproduct() {
      console.log("aaa");
      console.log(process.env);
    },
    async productList() {
      const {
        data: res
      } = await productList(1);
      console.log(res);
      this.tableData = res;
    },
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.setContainerHeight);
  },
};
</script>

<style>
.el-header {

  background-color: #041a63
    /* #337ecc*/
  ;
  color: #ffffff;
  line-height: 50px;
}

.el-aside {
  color: #041a63;
}


</style>
